import Utf8 from 'crypto-js/enc-utf8';
import AES from 'crypto-js/aes';
import CryptoJS from 'crypto-js/crypto-js';
import Pkcs7 from 'crypto-js/pad-pkcs7';
import Base64 from 'crypto-js/enc-base64';

/**
 * 加密字符串
 * @param {String} s 
 */
export function encryptText(s, hex = false) {
  let key = Utf8.parse('bm6ee2k4ea2j22uu');
  let iv = Utf8.parse('zw2c6so93wl1v0ak');
  //AES加密
  let encrypted = AES.encrypt(s, key, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: Pkcs7
  });
  if (hex) {
    return encrypted.ciphertext.toString().toUpperCase();
  }
  return Base64.stringify(encrypted.ciphertext);
}
